package live.common;

import java.net.MalformedURLException;
import java.util.List;

import net.sf.json.JSONArray;

import org.dom4j.DocumentException;

import yfg.lm.staticdata.entity.StaticBusiness;
import yfg.lm.staticdata.entity.StaticRegion;
import yfg.lm.staticdata.service.BusinessService;
import yfg.lm.staticdata.service.RegionService;

public class ReaderXmlFile {

	public List<StaticBusiness> returnBusiness(String cityCode) {
		List<StaticBusiness> list = null;
		try {
			list = new BusinessService().returnBusiness(cityCode);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	public JSONArray returnBusinessJsonArray(String cityCode) {
		JSONArray result = null;
		List<StaticBusiness> list = returnBusiness(cityCode);
		if (list != null && list.size() > 0) {
			result = JSONArray.fromObject(list);
		}
		return result;
	}

	public List<StaticRegion> returnRegions(String cityCode) {
		List<StaticRegion> list = null;
		try {
			list = new RegionService().returnRegions(cityCode);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	public JSONArray returnRegionsJsonArray(String cityCode) {
		JSONArray result = null;
		List<StaticRegion> list = returnRegions(cityCode);
		if (list != null && list.size() > 0) {
			result = JSONArray.fromObject(list);
		}
		return result;
	}

}
